﻿using System;

namespace AzukiMap.DataSource
{
    public enum DataTypes
    {
        Point = 0,
        Polygon,
        MultiPolygon,
        MultiPoint,
        MultiLineString,
        LineString,
        LinearRing,
        GeometryCollection,
        Raster,
        Tile
    }

    public class DataType
    {
        DataTypes _type;

        string[] _DataTypesRev = 
        {
            "Point",
            "Polygon",
            "MultiPolygon",
            "MultiPoint",
            "MultiLineString",
            "LineString",
            "LinearRing",
            "GeometryCollection",
            "Raster",
            "Tile"
        };

        public DataTypes Type
        {
            set { _type = value; }
            get { return _type; }
        }

        public DataType(DataTypes type)
        {
            _type = type;
        }

        public DataType(string TypeString)
        {
            SetDataTypeByString(TypeString);
        }

        public void SetDataTypeByString(string TypeString)
        {
            bool matched = false;
            for (int i = 0; i < _DataTypesRev.Length; i++)
            {
                if (TypeString.Equals(_DataTypesRev[i], StringComparison.CurrentCultureIgnoreCase))
                {
                    matched = true;
                    _type = (DataTypes)i;
                }
            }
            if (matched == false)
            {
                throw new FormatException("Layer type string is not correct.");
            }
        }

        public string GetDataTypeByString()
        {
            string typeStr = _DataTypesRev[(int)_type];
            return typeStr;
        }

    }
}
